<?php

/**
 * ShopProductModel 模型
 * Class ShopProductModel
 */
class ShopProductModel extends BaseModel
{

    public $tableName = "shop_product";
    public $errMsg = '';

    static private $_singleton;

    public function __construct()
    {
        parent::__construct($this->tableName);
    }

    static public function getSingleton()
    {
        if (!self::$_singleton) {
            self::$_singleton = new static();
        }

        return self::$_singleton;
    }

    public function add($data)
    {
        try {
            $selfModel = static::getSingleton();
            return $selfModel->insert([
                'user_id'    => $data['user_id'],
                'product_id'       => $data['product_id'],
                'buy_num'          => $data['buy_num'],
                'create_time'   => time()
            ]);
        } catch (Exception $e) {
            $this->errMsg = $e->getMessage();
            return false;
        }
    }


}